/*
 * @Author: 飞越疯人院 353362604@qq.com
 * @Date: 2022-09-22 09:22:54
 * @LastEditors: 飞越疯人院 353362604@qq.com
 * @LastEditTime: 2022-12-22 15:22:55
 * @FilePath: \adminstration\src\Common\Modal\TwoModalList\SampleParameter.jsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { SaveExcelButton, OpenExcelButton } from '../Common/options'
import { LabReportTemplates } from '../Common/Conversion'

export const SampleAddParameter = async ({ OptionsEvent, oneData, Permission, actionRef }) => {
    const { LabReportEnum } = await LabReportTemplates()
    let dataList = {
        uuid: oneData.uuid,
        hideInSearch: true,
        pageSize: 10,
        params: { sampleUuid: oneData.uuid },
        get: API_LIST([oneData.uuid])['getSampleItem'],
        columns: [
            commonTableList.uuid,
            {
                dataIndex: 'sampleUuid',
                title: '样品编号',
                type: 'hidden',
                hideInTable: true,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                width: 150,
            },
            {
                dataIndex: 'displayNo',
                title: '样品编号',
                type: 'hidden',
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                width: 150,
            },
            {
                dataIndex: 'serialNo',
                title: '报告编号',
                type: 'hidden',
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                width: 150,
            },
            {
                dataIndex: 'labReportTemplateUuid',
                title: '报告名称',
                valueType: 'select',
                valueEnum: LabReportEnum,
                rules: true,
                hideInSearch: true,
                width: 200,
            },
            {
                dataIndex: 'selectedTestTypes',
                title: '检测参数',
                type: 'hidden',
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                width: 300,
                render: (_, res) => {
                    const { selectedTestTypes, labReportTemplateUuid, uuid: SampleItemUuid } = res
                    return (
                        <div>
                            {selectedTestTypes.map(({ uuid, tableName, labDataSourceUuid }) => {
                                if (labDataSourceUuid === '7ffd2f4f-e3e7-4a44-ba0f-561781fb9de5') {
                                    return (
                                        <OpenExcelButton
                                            key={uuid}
                                            title={tableName}
                                            OptionsEvent={OptionsEvent}
                                            data={{
                                                save: true,
                                                submit: true,
                                                SampleItemUuid,
                                                TestTypeUuid: uuid,
                                                url: 'getSampleItemGetTestDataEXCEL',
                                                pos: 'posSampleItemUploadTestDataEXCEL',
                                                LabReportTemplatesUuid: labReportTemplateUuid,
                                            }}
                                        />
                                    )
                                } else return false
                            })}
                        </div>
                    )
                },
            },
            {
                dataIndex: 'tableName',
                title: '样品名称',
                valueType: 'input',
                rules: true,
                width: 150,
            },
            {
                dataIndex: 'spec',
                title: '规格型号',
                valueType: 'input',
                hideInSearch: true,
                width: 100,
            },
            {
                dataIndex: 'num',
                title: '数量',
                valueType: 'inputNumber',
                rules: true,
                hideInSearch: true,
                width: 100,
            },
            {
                dataIndex: 'unit',
                title: '单位',
                valueType: 'input',
                hideInSearch: true,
                rules: true,
                width: 80,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 150,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    return [
                        <SaveExcelButton
                            key="excel"
                            title="下载报告"
                            api={API_LIST()['getLabReport']}
                            data={{ SampleItemUuid: record.uuid }}
                        />,
                    ]
                },
            },
        ],
    }
    return dataList
}
